Flutter / GetX Steps / Step8: Screen - form page
Screen - Form Page
-
Steps
1. in view
import 'package:flutter/material.dart'; import 'package:vera/controllers/login_controller.dart'; import 'package:get/get.dart'; import 'package:vera/models/user_model.dart'; import 'package:vera/widgets/bottom_nav.dart'; class LoginPage extends StatelessWidget { @override final LoginController controller = Get.put(LoginController()); // To listen to the changes in the textfield. TextEditingController _name = TextEditingController(); TextEditingController _email = TextEditingController(); TextEditingController _phoneno = TextEditingController(); Widget build(BuildContext context) { List userList = controller.userList; return GetBuilder ( builder: (controller) => Scaffold( body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( padding: const EdgeInsets.all(25), child: TextField( // To set the appropriate controller to the text field. controller: _name, decoration: InputDecoration( border: OutlineInputBorder(), labelText: "Enter your Name"), ), ), Padding( padding: const EdgeInsets.all(25), child: TextField( controller: _email, decoration: InputDecoration( border: OutlineInputBorder(), labelText: "Enter your Email"), ), ), Padding( padding: const EdgeInsets.all(25), child: TextField( controller: _phoneno, decoration: InputDecoration( border: OutlineInputBorder(), labelText: "Enter your Phone Number"), ), ), // Button to go to nextpage. ElevatedButton( onPressed: () { }, child: Text("SEND")) ], ), ), //bottomNavigationBar:BottomNavBar() ) ); } } 2. Controller
move the input controller variables to getXController
TextEditingController _name = TextEditingController(); TextEditingController _email = TextEditingController(); TextEditingController _phoneno = TextEditingController();